package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.domain.vo.OutapiLogVo;
import com.ruoyi.system.service.IOutapiVisitLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 对外接口访问日志Controller
 *
 * @author wjialong
 */
@RestController
@RequestMapping("/outapi/log")
public class OutapiVisitLogController extends BaseController {
    @Autowired
    private IOutapiVisitLogService logService;

    /**
     * 查询对外接口访问日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OutapiLogVo outapiLogVo,
                              Double maxTime, Double minTime) {
        startPage();
        List<OutapiLogVo> list = logService.getOutapiLogVo(outapiLogVo, maxTime, minTime);
        return getDataTable(list);
    }


    /**
     * 获取对外接口访问日志详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        String remark = logService.selectOutapiVisitLogById(id).getRemark();
        if (remark == null) {
            return AjaxResult.error("信息不存在");
        }
        return AjaxResult.success(remark);
    }
//    /**
//     * 导出对外接口访问日志列表
//     */
//    @RequiresPermissions("system:log:export")
//    @Log(title = "对外接口访问日志", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, OutapiVisitLog outapiVisitLog) {
//        List<OutapiVisitLog> list = logService.selectOutapiVisitLogList(outapiVisitLog);
//        ExcelUtil<OutapiVisitLog> util = new ExcelUtil<OutapiVisitLog>(OutapiVisitLog.class);
//        util.exportExcel(response, list, "对外接口访问日志数据");
//    }
//    /**
//     * 新增对外接口访问日志
//     */
//    @RequiresPermissions("system:log:add")
//    @Log(title = "对外接口访问日志", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody OutapiVisitLog outapiVisitLog) {
//        return toAjax(logService.insertOutapiVisitLog(outapiVisitLog));
//    }
//
//    /**
//     * 修改对外接口访问日志
//     */
//    @RequiresPermissions("system:log:edit")
//    @Log(title = "对外接口访问日志", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody OutapiVisitLog outapiVisitLog) {
//        return toAjax(logService.updateOutapiVisitLog(outapiVisitLog));
//    }
//
//    /**
//     * 删除对外接口访问日志
//     */
//    @RequiresPermissions("system:log:remove")
//    @Log(title = "对外接口访问日志", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable String[] ids) {
//        return toAjax(logService.deleteOutapiVisitLogByIds(ids));
//    }
}
